<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

<script>
// 数据类型转换通常指将其他数据类型转成 字符串 数字 布尔值
// 数据类型转换有两种: 强制转换(显式转换) 和 自动转换(隐式转换)

// 强制转换(显式转换): 其他类型 转成 字符串
var str = 'hello';
var num = 123;
var boo = true;
var nul = null;
var und = undefined;
var obj = {a:1,b:2};
var fun = function (){};
var arr1 = [];
var arr2 = [6];
var arr3 = [7,8,9];

/* // val.toString()将val转成字符串值(null和undefined不能转)
console.log( str.toString() );// 'hello'
console.log( num.toString() );// '123'
console.log( boo.toString() );// 'true'
// console.log( nul.toString() );// 报错 *
// console.log( und.toString() );// 报错 *
console.log( obj.toString() );// '[object Object]' *
console.log( fun.toString() );// 'function (){}'
console.log( arr1.toString() );// '' *
console.log( arr2.toString() );// '6' *
console.log( arr3.toString() );// '7,8,9' *
 */


// String(val)将val转成字符串值(null和undefined也能转)
console.log( String(str) );// 'hello'
console.log( String(num) );// '123'
console.log( String(boo) );// 'true'
console.log( String(nul) );// 'null'
console.log( String(und) );// 'undefined'
console.log( String(obj) );// '[object Object]'
console.log( String(fun) );// 'function (){}'
console.log( String(arr1) );// ''
console.log( String(arr2) );// '6'
console.log( String(arr3) );// '7,8,9'

</script>
</body>
</html>